<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="__COMPONENT__/pear/css/pear.css" />
    <link rel="stylesheet" href="__COMPONENT__/layui/css/layui.css" />
</head>
<body class="pear-container">
<form class="layui-form layui-form-pane" method="post">
    <div class="layui-tab-item layui-show layui-col-md6 layui-col-md-offset2">
        <div class="layui-form-item">
            <label class="layui-form-label">分类标题</label>
            <div class="layui-input-block">
                <input type="text" name="name" required  lay-verify="required" placeholder="请输入标题" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">级别类型</label>
            <div class="layui-input-block">
                <input type="text" name="pid" value="0" id="tree" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分类排序</label>
            <div class="layui-input-block">
                <input type="number" name="sort" placeholder="分类排序" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分类状态</label>
            <div class="layui-input-block">
                <input type="checkbox" checked="" name="status" lay-skin="switch" lay-filter="switchStatus" title="开关">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">SEO关键字</label>
            <div class="layui-input-block">
                <textarea name="seo_keywords" placeholder="请输入SEO关键词，请使用逗号隔开" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">SEO描述</label>
            <div class="layui-input-block">
                <textarea name="seo_description" placeholder="请输入SEO描述，内容请不要超过100字" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <div class="layui-input-block">
                <button type="submit" id="save" class="layui-btn" lay-submit="" lay-filter="save">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>
<script src="__COMPONENT__/layui/layui.js"></script>
<script src="__COMPONENT__/pear/pear.js"></script>
<script>
    layui.use(['treeSelect','form','jquery','notice'], function () {
        var treeSelect= layui.treeSelect;
        var $ = layui.jquery;
        var form = layui.form;
        var notice = layui.notice;

        //加载下拉树
        treeSelect.render({
            // 选择器
            elem: '#tree',
            //请求类型
            type:'post',
            // 数据
            data: '/admin.php/tagscategory/tree',
            // 占位符
            placeholder: '默认顶级分类',
            // 是否开启搜索功能：true/false
            search: true,
            // 点击回调
            click: function(d){
                $("#tree").val(d.current.id)
            }
        });

        //提交数据
        form.on('submit(save)', function(data){
            if (data.field.status=='on'){
                data.field.status = 1;
            }else{
                data.field.status = 0;
            }
            $.ajax({
                type:'post',
                url: "/admin.php/tagscategory/add",
                data:data.field,
                success:function(result){
                    if(result.code==1){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }else{
                        notice.error(result.msg)
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>
